package com.aboo.zookeeper.service;

import com.aboo.frame.util.ZkClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ZookeeperService {

    public boolean create(String path, String data) {
        try {
            ZkClient.create(path, data);
        } catch (Exception e) {
            log.error("创建失败", e);
            return false;
        }

        return true;
    }

    public String query(String path) {
        String data = null;
        try {
            data = ZkClient.queryData(path);
        } catch (Exception e) {
            log.error("查询失败", e);
            data = null;
        }

        return data;
    }

    public boolean update(String path, String data) {
        try {
            ZkClient.update(path, data);
        } catch (Exception e) {
            log.error("更新失败", e);
            return false;
        }

        return true;
    }

    public boolean delete(String path) {
        try {
            ZkClient.delete(path);
        } catch (Exception e) {
            log.error("删除失败", e);
            return false;
        }

        return true;
    }

}
